package com.lp.company.controller;

import com.lp.common.entity.Result;
import com.lp.company.service.CompanyService;
import com.lp.domain.company.Company;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lipengak
 * @Description
 * @Date 2020/1/31 1:18
 * @Copyright 2019-2020
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/company")
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    /**
     * 保存企业
     */
    @PostMapping()
    public Result add(@RequestBody Company company) {
        companyService.add(company);
        return Result.SUCCESS();
    }

    /**
     * 更新企业
     */

    @PutMapping(value = "/{id}")
    public Result update(@PathVariable String id, @RequestBody Company company) {
        company.setId(id);
        companyService.update(company);
        return Result.SUCCESS();
    }

    /**
     * 删除
     */
    @DeleteMapping(value = "/{id}")
    public Result deltet(@PathVariable(value = "id") String id) {
        companyService.deleteById(id);
        return Result.SUCCESS();
    }

    /**
     * 根据id查询企业
     */
    @GetMapping(value = "/{id}")
    public Result findById(@PathVariable(value = "id") String id) {
        return Result.SUCCESS(companyService.findById(id));
    }


    /**
     * 查询所有企业
     */
    @CrossOrigin
    @GetMapping()
    public Result findAll() {
        return Result.SUCCESS(companyService.findAll());
    }



}

